package com.lzm.back.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzm.back.entity.Event;
import com.lzm.back.mapper.EventMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EventService {

    @Resource
    private EventMapper eventMapper;

    public void addEventInformation(Event event) {
        eventMapper.insert(event);
        System.out.println(event);
    }

    public void deleteEventInformation(Event event) {
        //删除赛事信息
        eventMapper.deleteByPrimaryKey(Long.valueOf(event.getId()));
    }
    //根据id删除赛事信息
    public void deleteEventInformationById(Long id) {
        eventMapper.deleteByPrimaryKey(id);
    }
    //批量删除赛事信息
    public void deleteEventInformationBaTch(List<Long> ids) {
        for (Long id : ids) {
            eventMapper.deleteByPrimaryKey(id);
        }
    }

    public void updateEventInformation(Event event) {
        eventMapper.updateByPrimaryKey(event);
        System.out.println(event);
    }

    /**
     * @param event
     * @param location 赛事地点
     * @param name     赛事名字
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<Event> selectPage(Event event, String location,
                                      String name, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        List<Event> eventList = eventMapper.selectByCondition(name, location, event.getCategoryId());

        return PageInfo.of(eventList);
    }


}
